/*
 * CS_APPLY_STAT_POINT.cpp
 *
 *  Created on: 2013. 5. 21.
 *      Author: the2
 */

#include "../../User.h"
#include "CS_APPLY_STAT_POINT.h"

namespace ProjectZ { namespace NCommand { namespace NAbility {

void CS_APPLY_STAT_POINT::OnExecute(User * pUser, ::Network::Packet * pPacket)
{
	PREPARE_PACKET;

	uint16_t str = 0;
	uint16_t dex = 0;
	uint16_t con = 0;
	uint16_t spi = 0;

	*pPacket >> str >> dex >> con >> spi;
	//pPacket->ParseMsg("%2d%2d%2d%2d%2d", &str, &dex, &con, &spi, &zen_sub_stat);

	uint32_t changesum = str + dex + con + spi;

	uint16_t ackReturn = ACK_OK;
	if (pUser->GetCharacterInfo().remain_stat_point < changesum)
	{
		ackReturn = ACK_UNKNOWN_ERROR;
		DEBUGLOG("CS_APPLY_STAT_POINT invalid stat point - remain: %d, str: %d, dex: %d, con: %d, spi: %d",
				pUser->GetCharacterInfo().remain_stat_point, str, dex, con, spi);
	}
	else
	{
		pUser->GetCharacterInfo().str += str;
		pUser->GetCharacterInfo().dex += dex;
		pUser->GetCharacterInfo().con += con;
		pUser->GetCharacterInfo().spi += spi;

		pUser->GetCharacterInfo().remain_stat_point -= changesum;
	}

	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
	pAck->MsgCat("%2d", ackReturn);
	pAck->MakePacket(CMD_SC_APPLY_STAT_POINT);
	pUser->Send(pAck);
}

} /*NAbility*/ } /*NCommand*/ } /*ProjectZ*/
